﻿@page "/auth"
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization

@* <AuthorizeView>
    <NotAuthorized>
        <button>登录</button>
    </NotAuthorized>
    <Authorized>
    用户名： @context?.User?.Identity?.Name
    </Authorized>
</AuthorizeView> *@

@if (User is not null && User.Identity is not null)
{
    if(User.Identity.IsAuthenticated){
        @User?.Identity?.Name
    }
    else
    {
        <button @onclick="Login">登录</button>
    }
}
else
{
    <button @onclick="Login">登录</button>
}

@inject AuthenticationStateProvider StateProvider

@code {
    // [CascadingParameter]Task<AuthenticationState> StateTask{ get; set; }

    ClaimsPrincipal? User{ get; set; }

    async Task Login()
    {
        var state= await StateProvider.GetAuthenticationStateAsync();

        User = state.User;
    }
}
